package algorithm.search;

public class _0_5Search {
    public static void main(String[] args) {
        Integer[] integer = {1, 2, 43, 78, 89, 100, 456, 789, 4645, 7878};
        //二分查找，使用条件，容器里的元素必须有序，返回是否存在
        int user = 10;
        System.out.println(getsearch(integer, user));
    }

    public static boolean getsearch(Integer[] arr, int user) {
        int min = 0;
        int max = arr.length - 1;
        while (true) {
            if (min > max) {
                return false;
            }
            int middle = 0;
            middle = (min + max) / 2;
            if (user == arr[middle]) {
                return true;
            } else if (arr[middle] > user) {
                max = middle - 1;
            } else {
                min = middle + 1;
            }
        }
    }
}
